//
//  CRButton.m
//  CRChatRoom
//
//  Created by lanou3g on 15/11/19.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRButton.h"
#import "CRBadgeButton.h"
#define titleFont [UIFont boldSystemFontOfSize:14]

@interface CRButton ()
/**
 *  提醒数字按钮
 */
@property (nonatomic, strong) CRBadgeButton *badgeButton;

@end

@implementation CRButton

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        // 一次性设置
        self.imageView.contentMode = UIViewContentModeCenter;
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.titleLabel.font = titleFont;
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        // 添加提醒数字按钮
        self.badgeButton = [[CRBadgeButton alloc] init];
        [self addSubview:self.badgeButton];
        
        
    }
    return self;
}

// 自定义按钮内部label和imageview位置
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
    
    CGFloat imageW = contentRect.size.width;
    CGFloat imageH = contentRect.size.height * 0.6;
    return CGRectMake(0, 0, imageW, imageH);
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
    
    CGFloat titleY = contentRect.size.height * 0.6;
    CGFloat titleW = contentRect.size.width;
    CGFloat titleH = contentRect.size.height - titleY;
    return CGRectMake(0, titleY, titleW, titleH);
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 设置提醒按钮的位置
    CGFloat X = self.frame.size.width / 2 + 13;
    CGFloat Y = 0;
    self.badgeButton.origin = CGPointMake(X, Y);
    self.badgeButton.badgeValue = @"1";
    

}
@end











